package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo17SparkStandaloneSubmit {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()

    /**
     * 如果将来在linux集群中运行，这里就不需要设置setMaster
     */
//    conf.setMaster("local")
    val sparkContext = new SparkContext(conf)

    val linesRDD: RDD[String] = sparkContext.parallelize(List("java,hello,world", "hello,scala,spark", "java,hello,spark"))

    val wordRDD: RDD[String] = linesRDD.flatMap(_.split(","))
    val wordKVRDD: RDD[(String, Int)] = wordRDD.map((_, 1))
    val countRDD: RDD[(String, Int)] = wordKVRDD.reduceByKey(_ + _)

    countRDD.foreach(println)

    /**
     *  将项目打包放到spark集群中使用standalone模式运行
     * standalone client
     * spark-submit --class com.shujia.core.Demo17SparkStandaloneSubmit --master spark://master:7077 --executor-memory 512m --total-executor-cores 1 spark-1.0.jar 100
     *
     * standalone cluster
     * spark-submit --class com.shujia.core.Demo17SparkStandaloneSubmit --master spark://master:7077 --executor-memory 512m --total-executor-cores 1 --deploy-mode cluster spark-1.0.jar 100
     *
     */

  }

}
